"""
Case Type   : 共享存储-工具-pg_controldata
Case Name   : 显示帮助信息
Create At   : 2023/4/11
Owner       : opentestcase019
Description :
    1.显示帮助信息
      pg_controldata --help/-?
Expect      :
    1.显示帮助信息正常
History     :
"""
import os
import unittest
from yat.test import Node
from yat.test import macro
from testcase.utils.Logger import Logger
from testcase.utils.Common import Common


class ShareStorageTool(unittest.TestCase):
    def setUp(self):
        self.logger = Logger()
        self.logger.info(f"-----{os.path.basename(__file__)} start-----")
        self.primary_node = Node('PrimaryDbUser')
        self.common = Common()
        self.expect_msg = '''pg_controldata displays control information of \
an openGauss database cluster.

Usage:
  pg_controldata [OPTION] [DATADIR]

Options:
  -I, --instance-id=INSTANCE_ID
                    display information of specified instance (default all)
      --enable-dss  enable shared storage mode
      --socketpath=SOCKETPATH
                    dss connect socket file path
  -V, --version     output version information, then exit
  -?, --help        show this help, then exit

If no data directory (DATADIR) is specified, the environment variable PGDATA
is used.

Report bugs to community@opengauss.org> or join opengauss community \
<https://opengauss.org>'''

    def test_sharestorage_tool(self):
        step1 = "-----step1:显示帮助信息;expect:显示帮助信息正常-----"
        self.logger.info(step1)
        execute_cmd = f"source {macro.DB_ENV_PATH};pg_controldata --help"
        self.logger.info(execute_cmd)
        execute_msg = self.common.get_sh_result(self.primary_node, execute_cmd)
        self.assertIn(self.expect_msg, execute_msg, "执行失败" + step1)
        execute_cmd = f"source {macro.DB_ENV_PATH};pg_controldata -?"
        self.logger.info(execute_cmd)
        execute_msg = self.common.get_sh_result(self.primary_node, execute_cmd)
        self.assertIn(self.expect_msg, execute_msg, "执行失败" + step1)

    def tearDown(self):
        self.logger.info("-----无需环境清理-----")
        self.logger.info(f"-----{os.path.basename(__file__)} end-----")
